package com.wwwarehouse.financialcenter.fragment.moneywarehouse.billingrecords;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.financialcenter.R;
import com.wwwarehouse.financialcenter.fragment.base.TheParentFragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Joseph on 2017/11/15.
 *         <p/>
 *         订单详情,废弃。接入项正旺模块
 */
public class ChargingOrderDetailsFragment extends TheParentFragment implements View.OnClickListener {
    private ImageView mImgPhoto;
    private TextView mName, mType, mCount, mOrderTime;
    private TextView mWeekPay, mOrderPay, mBankCardPay, mAliPay, mWechatPay, mOfflinePay;
    private TextView mTotalMoney, mAddress, mContant;
    private Button mBtnConfrim, mBtnTermationOrder, mCheckOrderGoods;
    private int mFlag = 0;
    private String businessId;
    private ArrayList<String> mBusinessIdList;
    private String contractUkid;

    @Override
    protected int getContentId() {
        return R.layout.financial_center_charging_order_details;
    }
    @Override
    public void setTitle() {
        if (peekFragment() instanceof ChargingOrderDetailsFragment) {
            mActivity.setTitle(getString(R.string.financial_center_order_details));
        }
    }
    @Override
    protected void loadDatas() {
        if (getArguments() != null) {
            mFlag = getArguments().getInt("flag", 0);
            if (mFlag == 1) {
                String stopId = getArguments().getString("stopId");
                String contractid = getArguments().getString("contractUkid");
                if (!TextUtils.isEmpty(stopId) && !TextUtils.isEmpty(contractid)) {
                    mBusinessIdList.add(stopId);
                    contractUkid = contractid;
                } else {
                    mBusinessIdList = getArguments().getStringArrayList("businessIds");
//                    mTerminationBean = getArguments().getParcelable("listbean");
//                    contractUkid = mTerminationBean.getContractUkid();
                }
            } else {
//                mListBean = getArguments().getParcelable("listbean");
                businessId = getArguments().getString("businessId");
                mBusinessIdList.add(businessId);
//                contractUkid = mListBean.getContractUkid();
            }

        }

        //mFlag==1是信息卡片跳转过来的
        if (mFlag == 1) {
            mCheckOrderGoods.setVisibility(View.VISIBLE);
            mBtnTermationOrder.setVisibility(View.GONE);
            mBtnConfrim.setVisibility(View.VISIBLE);
        } else {
            mCheckOrderGoods.setVisibility(View.GONE);
            mBtnTermationOrder.setVisibility(View.VISIBLE);
            mBtnConfrim.setVisibility(View.GONE);
        }
    }

    @Override
    protected void init(View view) {
        mImgPhoto = $(R.id.detial_image);
        mName = $(R.id.detial_name);
        mType = $(R.id.detial_type);
        mCount = $(R.id.detial_count);
        mOrderTime = $(R.id.detial_order_time);
        mWeekPay = $(R.id.detial_weekpay);
        mOrderPay = $(R.id.detial_orderpay);
        mBankCardPay = $(R.id.detial_bankcardpay);
        mAliPay = $(R.id.detial_alipay);
        mWechatPay = $(R.id.detial_wechatpay);
        mOfflinePay = $(R.id.detial_offlinepay);
        mTotalMoney = $(R.id.detial_totalmoney);
        mAddress = $(R.id.detial_address);
        mContant = $(R.id.detial_contant);
        mBtnConfrim = $(R.id.btn_confirm);
        mBtnTermationOrder = $(R.id.btn_terminationorder);
        mCheckOrderGoods = $(R.id.btn_check_ordergoods);
        mBusinessIdList = new ArrayList<>();
        mBtnConfrim.setOnClickListener(this);
        mBtnTermationOrder.setOnClickListener(this);
        mCheckOrderGoods.setOnClickListener(this);
    }

    @Override
    public void requestDatas() {
        Map<String, Object> map = new HashMap<>();
        map.put("contractUkid", contractUkid);
        map.put("businessIds", mBusinessIdList);
//        NoHttpUtils.httpPost(ContractConstant.GET_ORDER_PAYMENT_DETAIL, map, mOnResponseListener, 0);

    }

    @Override
    public void onSuccess(CommonClass commonClass, int what) {

    }

    @Override
    public void onReLoad(int code) {

    }


//    private void setData(ConstractOrderDetailsBean orderDetailsBean) {
//        ImageloaderUtils.displayImg(ImageloaderUtils.getImageLoader(), orderDetailsBean.getLogoUrl(), mImgPhoto);
//        mName.setText(orderDetailsBean.getBusinessName());
//        mType.setText("商品种类：" + orderDetailsBean.getSkuCount());
//        mCount.setText("商品件数：" + orderDetailsBean.getItemCount());
//        mOrderTime.setText("下单时间：" + orderDetailsBean.getContractTime());
//
//        mWeekPay.setText(Html.fromHtml("周期付金额：<font color='#337CFF'>" + orderDetailsBean.getPeriodPay() + "元</font>"));
//        mOrderPay.setText(Html.fromHtml("下单付金额：<font color='#337CFF'>" + orderDetailsBean.getOrderPay() + "元</font>"));
//        if (0 == orderDetailsBean.getBank()) {
//            mBankCardPay.setVisibility(View.GONE);
//        } else {
//            mBankCardPay.setText("银行卡支付：" + orderDetailsBean.getBank() + "元");
//        }
//        if (0 == orderDetailsBean.getAliPay()) {
//            mAliPay.setVisibility(View.GONE);
//        } else {
//            mAliPay.setText("支付宝支付：" + orderDetailsBean.getAliPay() + "元");
//        }
//
//        if (0 == orderDetailsBean.getWechatPay()) {
//            mWechatPay.setVisibility(View.GONE);
//        } else {
//            mWechatPay.setText("微信支付：" + orderDetailsBean.getWechatPay() + "元");
//        }
//
//        if (0 == orderDetailsBean.getOffline()) {
//            mOfflinePay.setVisibility(View.GONE);
//        } else {
//            mOfflinePay.setText("线下支付：" + orderDetailsBean.getOffline() + "元");
//        }
//
//        mTotalMoney.setText(Html.fromHtml("合计：<font color='#337CFF'>" + orderDetailsBean.getTotalPrice() + "元</font>"));
//        mAddress.setText("配送地址：" + orderDetailsBean.getAddress());
//        String contant = "";
//        if (!TextUtils.isEmpty(orderDetailsBean.getReceiveName())) {
//            contant = "联系人：" + orderDetailsBean.getReceiveName() + "\t\t";
//        }
//        if (!TextUtils.isEmpty(orderDetailsBean.getMobilePhone())) {
//            contant += orderDetailsBean.getMobilePhone() + "\t";
//        }
//
//        mContant.setText(contant);
//
//    }


    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.btn_terminationorder) {
//            SecondaryConfirmationFragment confirmationFragment = new SecondaryConfirmationFragment();
//            Bundle bundle = new Bundle();
//            bundle.putString("businessId", businessId);
//            bundle.putInt("flag", 1);
//            bundle.putParcelable("listbean", mListBean);
//            confirmationFragment.setArguments(bundle);
//            pushFragment(confirmationFragment);

        } else if (i == R.id.btn_check_ordergoods) {
//            ConstractProductDetailsViewPagerFragment productDetailsViewPagerFragment = new ConstractProductDetailsViewPagerFragment();
//            Bundle bundle = new Bundle();
//            bundle.putInt("flag", 1);
//            bundle.putParcelable("orderbean", mOrderDetailsBean);
//            bundle.putParcelable("listbean", mTerminationBean);
//            bundle.putString("contractUkid",contractUkid);
//            productDetailsViewPagerFragment.setArguments(bundle);
//            pushFragment(productDetailsViewPagerFragment);

        } else if (i == R.id.btn_confirm) {
            popFragment();
        }
    }
}
